package customControls;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.example.jaden.washer.*;

import activity.HomePage;
import activity.OrderPage;
import activity.PersonalinfoPage;


//自定义控件 导航栏
//由三个按钮组成，分别是 首页 订单页 和个人信息页
public class NavigationbarLayout extends ConstraintLayout implements View.OnClickListener {
    Button homepage;
    Button order;
    Button personalinfo;

    public NavigationbarLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        //动态加载指定布局R.layout.navigation_bar
        LayoutInflater.from(context).inflate(R.layout.navigation_bar, this);
        //获取控件实例
        getInstance();
        //三个按钮执行点击事件  点击后 在onClick中执行
        setClickListener();
    }

    //获取控件实例
    private void getInstance() {
        homepage = (Button) findViewById(R.id.button_homepage_navigationbar);
        order = (Button) findViewById(R.id.button_order_navigationbar);
        personalinfo = (Button) findViewById(R.id.button_personalinfomation_navigationbar);
    }
    //执行按键点击监听
    private void setClickListener() {
        homepage.setOnClickListener(this);
        order.setOnClickListener(this);
        personalinfo.setOnClickListener(this);
    }

        @Override
    public void onClick(View v) {
       Intent intent;
       Context context=getContext();
        switch (v.getId()){
            case R.id.button_homepage_navigationbar:
                intent=new Intent(context, HomePage.class);
                context.startActivity(intent);
                break;
            case R.id.button_order_navigationbar:
                intent=new Intent(context, OrderPage.class);
                context.startActivity(intent);
                break;
            case R.id.button_personalinfomation_navigationbar:
                intent=new Intent(context, PersonalinfoPage.class);
                context.startActivity(intent);
                break;
                default:
                    break;

        }
    }
}
